class Scan < ActiveRecord::Base
 
    attr_accessible :scan_name, :system, :domain, :type, :pattern, :file, :offset, :md5, :tracker, :number, :profile
   
    validates_presence_of :scan_name, :profile, :system

    has_one :profiles
    accepts_nested_attributes_for :profiles
    
    AGENTLESS_WIN_BIN = "perl vendor/scanners/agentless-win.pl "
    AGENTLESS_UNIX_BIN = "perl vendor/scanners/agentless-unix.pl "
    AGENTLESS_DB_BIN = "perl vendor/scanners/agentless-db.pl "
    AGENT_WIN_BIN = "perl vendor/scanners/opendlp.exe "

    def self.run_scan(scan_type, profile, tracker, system, scan_name)
        
        begin
          case scan_type
              # -- 
              # -- Windows Agent
              # -- 
              when 'win_agent' then
                  
                  system(AGENT_WIN_BIN + " " + profile.to_s + " " + system.to_s + " " + tracker.to_s + " " + scan_name.to_s)

              # --
              # -- Windows Agentless
              # -- 
              when 'win_agentless' then
                  
                  system(AGENTLESS_WIN_BIN + " " + profile.to_s + " " + system.to_s + " " + tracker.to_s + " " + scan_name.to_s)

              # -- 
              # -- Windows Share Network
              # -- 
              when 'win_share' then
                  
                  system(AGENTLESS_WIN_BIN + " " + profile.to_s + " " + system.to_s + " " + tracker.to_s + " " + scan_name.to_s)

              # -- 
              # -- UNIX Agentless
              # -- 
              when 'unix_agentless' then
                  
                  system(AGENTLESS_UNIX_BIN + " " + profile.to_s + " " + system.to_s + " " + tracker.to_s + " " + scan_name.to_s)

              # -- 
              # -- MySQL Agentless
              # -- 
              when 'mysql_agentless' then
                  
                  system(AGENTLESS_DB_BIN + " " + profile.to_s + " " + system.to_s + " " + tracker.to_s + " " + scan_name.to_s)

              # -- 
              # -- MSSQL Agentless
              # -- 
              when 'mssql_agentless' then
                  
                  system(AGENTLESS_DB_BIN + " " + profile.to_s + " " + system.to_s + " " + tracker.to_s + " " + scan_name.to_s)

              # -- 
              # -- PostgreSQL Agentless
              # -- 
              when 'postgresql_agentless' then
                  
                  system(AGENTLESS_DB_BIN + " " + profile.to_s + " " + system.to_s + " " + tracker.to_s + " " + scan_name.to_s)

              else 
                  return false
          end
        rescue SyntaxError, NameError => error
            return error
        end
    end

end
